FROM node:16-alpine
RUN wget https://gitee.com/clh21/sh/raw/master/mirror.sh && sh ./mirror.sh; rm -f mirror.sh
RUN apk update && apk add bash && \
    adduser -D -s /bin/bash dev && \
    echo "dev:dev" | chpasswd

# 安装 OpenSSH 服务和客户端
RUN apk add --no-cache openssh-server openssh-client bash && \
    ssh-keygen -A

# 配置 SSH 服务
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin no/' /etc/ssh/sshd_config && \
    sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config && \
    sed -i 's/ChallengeResponseAuthentication yes/ChallengeResponseAuthentication no/' /etc/ssh/sshd_config && \
    sed -i 's/UsePAM yes/UsePAM no/' /etc/ssh/sshd_config && \
    sed -i 's/PermitEmptyPasswords yes/PermitEmptyPasswords no/' /etc/ssh/sshd_config && \
    echo 'UseDNS no' >> /etc/ssh/sshd_config && \
    echo 'AllowUsers dev' >> /etc/ssh/sshd_config

# 配置用户目录
RUN echo 'export PS1="\[\e[32m\]\u@webssh2:\[\e[33m\]\w\[\e[0m\]\$ "'> /home/dev/.bash_profile && \
    chown -R dev:dev /home/dev

WORKDIR /usr/src
COPY app/ /usr/src/
RUN npm ci --audit=false --bin-links=false --fund=false
COPY config.json /usr/src/

EXPOSE 2222/tcp

COPY docker-entrypoint.sh /
RUN chmod +x /docker-entrypoint.sh
ENTRYPOINT [ "/docker-entrypoint.sh" ]

CMD [ "/usr/local/bin/node", "index.js" ]